package com.awakensoftware.hunterserver.serverentities;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Point;

@Entity
@Table(name = "Chests")
public class Chest extends ServerEntityBase {

	private static final long serialVersionUID = 5712057246564821049L;

	// Database fields and relationships
	@Id
	@Column(name = "id")
	@GeneratedValue
	private long id;

	@Column(length = 256, unique = false, name = "name")
	private String name;
	
	@Column(name = "locationpoint", columnDefinition = "Geometry", nullable = true) 
	@Type(type = "org.hibernate.spatial.GeometryType")
	private Point locationPoint;

	@OneToMany(mappedBy = "chest", fetch=FetchType.EAGER)
	private Set<Treasure> treasures = new HashSet<Treasure>();		
	
	@Override
	public long getId() {
		return id;
	}
	
	@Override
	public void setId(long id) {
		this.id = id;
	}

	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName(String name) {
		this.name = name;
	}	

	public Point getLocationPoint(){
		return this.locationPoint;
	}
	
	public void setLocationPoint(Point locationPoint) {
		this.locationPoint = locationPoint;		
	}
	
	public Set<Treasure> getTreasures() {
		return treasures;
	}	
	
	public boolean addTreasure(Treasure treasure) {
		return treasures.add(treasure);
	}		
	
}
